home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / lib / mntc6846.zoo / patch / xerror.spp < prev    next >
Encoding:
Text File  |  1994-11-14  |  3.2 KB  |  128 lines

  1. !  C68 Floating Point error routines
  2. !
  3. !  If return made from the raise() system call, then an
  4. !  appropriate value is passed back in d0 and d1.
  5. !
  6. !  The values involved are such that 'float' routines 
  7. !  can simply take the d0 value
  8. !
  9. !-----------------------------------------------------------------------------
  10. !  #1  First version (based on ideas from Michael Mueller)    djw-  09/93
  11. !-----------------------------------------------------------------------------
  12.  
  13.     .sect .text
  14.  
  15.     .define __huge_val
  16.     .define __infinity
  17.     .define __infinitydf
  18.     .define __NaN
  19.     .define __SNaN
  20.  
  21.     .define .overflow
  22.     .define .underflow
  23.     .define .divzero
  24.     .define .setmaxmin
  25.  
  26. !    This next bit handles the sizeof(int) problem
  27.  
  28. #include <errno.h>
  29. #include <signal.h>
  30.  
  31. #ifdef __MSHORT__
  32. #define LN    w
  33.     LEN =    2
  34. #else
  35. #define LN    l
  36.     LEN =    4
  37. #endif
  38.  
  39.  
  40. ! This is the representation of key floating point values.
  41. !
  42. ! It is done this way, because it is quite likely that  rounding errors
  43. ! in the compiler might mean the bit pattern is not exactly represented
  44. ! if simply done via a #define statement.
  45.  
  46.  
  47. ! Maximum Floating Point Number (can be signed)
  48. __huge_val:
  49.     .data4    0x7fefffff,0xffffffff
  50.  
  51. ! Infinity  (can be signed)
  52. __infinity:
  53. __infinitydf:
  54.     .data4    0x7ff00000,0x00000000
  55.  
  56. ! Not-a-Number
  57. __NaN:
  58.     .data4    0x7fffffff,0xffffffff
  59.  
  60. ! Signalling Not-a-Number
  61. __SNaN:
  62.     .data4    0xffffffff,0xffffffff
  63.  
  64.  
  65. ! Overflow has occurred
  66. ! We need to raise a floating point exception, with errno
  67. ! set to ERANGE.  If a return is made from the exception
  68. ! routine, then return HUGE_VAL
  69.  
  70. .overflow:
  71.     move.LN    #ERANGE,_errno        ! errno = ERANGE for overflow
  72.     bsr    sendsig
  73.     move.l    __huge_val(pc),d0    ! result = HUGE_VAL in case of return
  74.     move.l    __huge_val+4(pc),d1
  75.     rts
  76.  
  77. ! Underflow has occurred
  78. ! We need to raise a floating point exception, with errno
  79. ! set to ERANGE.  If a return is made from the floating
  80. ! routine, then return 0.
  81. !
  82. .underflow:
  83.     move.LN    #ERANGE,_errno        ! errno = ERANGE for underflow
  84.     bsr    sendsig
  85.     move.l    #0,d0            ! result = 0 in case of return
  86.     move.l    #0,d1
  87.     rts
  88.  
  89. ! Divide by Zero
  90. ! We need to raise a flaoting point exception with errno set to EDOM.
  91. ! If a return is made from the exception routine, then return infinity.
  92.  
  93. .divzero:
  94.     move.LN    #EDOM,_errno        ! errno = EDOM for  divide by zero
  95.     bsr    sendsig
  96.     move.l    __infinity(pc),d0    ! result = infinity in case of return
  97.     move.l    __infinity+4(pc),d1
  98.     rts
  99.  
  100. ! Send a signal.
  101. ! We also preserve A1 across this call as many of the FP support routines
  102. ! use this to hold a pointer to where the result is meant to be put.
  103. ! Most of the time we will not return from such a call, but ithe calling
  104. ! routines better be prepared to handle this just in case.
  105.  
  106. sendsig:
  107.     move.l    a1,-(sp)        ! save a1
  108.     move.LN    #SIGFPE,-(sp)        ! set for signal required
  109.     jsr    _raise            ! raise (SIGFPE) (with name hiding)
  110.     add.l    #LEN,sp            ! tidy up stack
  111.     move.l    (sp)+,a1        ! restore a1
  112.     rts
  113.  
  114. ! Set LONG_MAX or LONG_MIN
  115. ! This is used to set LONG_MAX or LONG_MIN according to the sign of the
  116. ! floating point number pointed to by 8(A0)
  117. ! (called by sftol() and dftol() routines)
  118.  
  119. .setmaxmin:
  120.     move.l  8(sp),a0        ! address of value
  121.     move.b  (a0),d1         ! get value
  122.     and.b    0x80,d1        ! isolate sign
  123.     bne    setmin        ! ... jump if negative
  124.     move.l    #0x7fffffff,d0    ! set to LONG_MAX
  125.     rts
  126. setmin:    move.l    #0x80000000,d0    ! set to LONG_MIN
  127.     rts
  128.